
import { _decorator, Component, Node, SpriteFrame, log, game, resources, Sprite } from 'cc';
import { EventManager } from './EventManager';
import { CommandType, MessageType } from './framework/Message';
import { MessageCenter } from './framework/MessageCenter';
import { Map } from './map/Map';
import { Hero } from './player/Hero';
import { Item } from './player/Item';
import { Move } from './player/Move';
import { Pet } from './player/Pet';
import { Utils } from './utils/Utils';
const { ccclass, property } = _decorator;

/**
 * Predefined variables
 * Name = GameData
 * DateTime = Sat Feb 05 2022 15:00:03 GMT+0800 (China Standard Time)
 * Author = vvc_zeng
 * FileBasename = GameData.ts
 * FileBasenameNoExtension = GameData
 * URL = db://assets/script/GameData.ts
 * ManualUrl = https://docs.cocos.com/creator/3.3/manual/zh/
 *
 */

@ccclass('GameData')
export class GameData extends Component {
    static Instance: GameData;
    // 各职业的文本说明
    heroTips = [
        ["刺客", "一个身手敏捷的刺客,初始命中和速度增加6"],
        ["国王", "一个威严的国王,初始智慧和幸运增加8"],
        ["骑士", "一个正直勇敢的骑士,初始攻击和速度增加8"],
        ["忍者", "一个狡猾善变的忍者,初始速度增加16,防御减少6"],
        ["法师", "一个充满智慧的法师,初始智慧增加20,防御减少6"],
        ["机器人", "一个来自未来的机器人,初始攻击和防御增加8"],
        ["侦探", "一个敏锐的侦探,初始命中增加12"],
        ["勇者♂", "一个男性勇士,初始体力增加10,攻击增加8"],
        ["勇者♀", "一个女性勇士,初始体力增加10,速度增加6"]
    ];
    // 一共i个职业的初始属性加成 [i][0]代表哪两项属性 [i][1]代表各增减多少数值
    heroData = [
        [[4, 6], [6, 6]],
        [[1, 5], [8, 8]],
        [[2, 6], [8, 8]],
        [[3, 6], [-6, 16]],
        [[1, 3], [20, -6]],
        [[2, 3], [8, 8]],
        [[4], [12]],
        [[0, 2], [10, 8]],
        [[0, 6], [10, 6]]
    ];
    // 各势力的文本说明
    factionTips = [
        ["花园", "秩序正义,增加生命、防御成长率"],
        ["异教", "混乱中立,增加生命、智慧成长率"],
        ["独眼", "混乱邪恶,增加智慧、命中成长率"],
        ["星月", "秩序中立,增加智慧、速度成长率"],
        ["全知之眼", "秩序中立,增加生命、攻击成长率"],
        ["剑与玫瑰", "秩序正义,增加攻击、速度成长率"],
        ["使徒", "混乱邪恶,攻击成长率翻倍,减少幸运成长率"],
        ["太阳纹章", "混乱正义,增加防御、幸运成长率"],
        ["权杖", "秩序邪恶,生命成长率翻倍,减少攻击成长率"],
        ["法典", "混乱正义,增加命中、幸运成长率"],
        ["三体", "混乱中立,增加攻击、防御、速度成长率,减少命中成长率"]
    ];
    // 各势力对成长率的初始加成
    factionData = [
        {
            type: "14",
            g: [[0, 3], [8, 3]]
        },
        {
            type: "03",
            g: [[0, 1], [8, 4]]
        },
        {
            type: "02",
            g: [[1, 4], [4, 2]]
        },
        {
            type: "13",
            g: [[1, 6], [4, 1]]
        },
        {
            type: "13",
            g: [[0, 2], [8, 3]]
        },
        {
            type: "14",
            g: [[2, 6], [3, 1]]
        },
        {
            type: "02",
            g: [[2, 5], [6, -1]]
        },
        {
            type: "04",
            g: [[3, 5], [3, 1]]
        },
        {
            type: "12",
            g: [[0, 2], [16, -3]]
        },
        {
            type: "04",
            g: [[4, 5], [2, 1]]
        },
        {
            type: "03",
            g: [[2, 3, 4, 6], [3, 3, -1, 1]]
        }
    ];
    // 各技能的说明
    moveTips = [
        ["剑斧双击", "临时提高0.4暴击"],
        ["爪击", "临时提高0.1速度0.3攻击"],
        ["掌心雷", "临时提高0.1暴击0.3命中"],
        ["双刃招架", "临时提高0.4幸运"],
        ["触手拍打", "30%造成缠绕1，20%造成眩晕1"],
        ["采掘", "碎裂1"],
        ["荷鲁斯之眼", "致死1"],
        ["魔法仙女棒", "闪亮之星1"],
        ["星落", "20%造成惊惧1"],
        ["齿咬", "受伤1"],
        ["火焰掌", "愤怒1"],
        ["天赐智慧", "20%造成咒术之剑"],
        ["天赐生命", "20%造成生命祝福"],
        ["踢击", "致残1"],
        ["直拳", "破碎武器1"],
        ["闪身", "速度+5幸运+4"],
        ["寒冰掌", "脆骨1"],
        ["冥想", "超级狙击1"],
        ["重拳", "20%造成晕眩"],
        ["窃取财物", "30%立即获得物品"],
        ["疾行", "速度暴涨+12"],
        ["火光一闪", "低落1"],
        ["收买", "20%造成混乱"],
        ["挥砍", "攻+5防+4"]
    ];
    // 各技能的发动效果
    moveData = [
        function (stat) {
            if (Math.random() < 0.5) {
                stat[7] += Math.round(0.4 * stat[1]);
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat) {
            if (Math.random() < 0.5) {
                stat[6] += Math.round(0.1 * stat[1]);
                stat[2] += Math.round(0.3 * stat[1]);
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat) {
            if (Math.random() < 0.5) {
                stat[7] += Math.round(0.1 * stat[1]);
                stat[4] += Math.round(0.3 * stat[1]);
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat) {
            if (Math.random() < 0.5) {
                stat[5] += Math.round(0.4 * stat[1]);
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat, tag, target, bq?) {
            // 对目标施加 debuff
            let _rate = Math.random();
            if (_rate > 0.7) {
                bq.push({ tag, target, id: 25, turn: 1 });
                console.log(`成功发动${this.name}`);
                console.log(`缠绕`);
            } else if (_rate < 0.2) {
                bq.push({ tag, target, id: 31, turn: 1 });
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 38, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 33, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target: tag, id: 13, turn: 1 });
            console.log(`成功对自己发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            if (Math.random() < 0.2) {
                bq.push({ tag, target, id: 34, turn: 1 });
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 24, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 27, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            if (Math.random() < 0.2) {
                bq.push({ tag, target: tag, id: 12, turn: 1 });
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat, tag, target, bq?) {
            if (Math.random() < 0.2) {
                bq.push({ tag, target: tag, id: 17, turn: 1 });
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 21, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 41, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat) {
            stat[5] += 5;
            stat[6] += 4;
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 23, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target: tag, id: 15, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            if (Math.random() < 0.2) {
                bq.push({ tag, target, id: 31, turn: 1 });
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat) {
            if (Math.random() > 0.7) {
                console.log("获得窃取的物品");
                Item.Instance.getItem(2);
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat) {
            stat[6] += 12;
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            bq.push({ tag, target, id: 26, turn: 1 });
            console.log(`成功发动${this.name}`);
        },
        function (stat, tag, target, bq?) {
            if (Math.random() < 0.2) {
                bq.push({ tag, target, id: 29, turn: 1 });
                console.log(`成功发动${this.name}`);
            }
        },
        function (stat) {
            stat[2] += 5;
            stat[3] += 4;
            console.log(`成功发动${this.name}`);
        }
    ];
    // 各事件的文本说明
    areaTips = [
        ["港口", "你可以在港口购买物品或低阶宠物"],
        ["地牢", "是否进入地牢？"],
        ["邪眼守卫", "战斗？交谈？无视？"],
        ["出口", "这是一处地牢或迷宫的出口"],
        ["人类守卫", "战斗？交谈？无视？"],
        ["士兵守卫", "战斗？交谈？无视？"],
        ["治疗守卫", "战斗？交谈？无视？"],
        ["传送门", "你可以传送到下一层"],
        ["迷宫挑战", "是否进入迷宫？"],
        ["塔庙", "祈祷？破坏？无视？"],
        ["亡者归来", "失去少量生命，可以复活最近死去的一只宠物"],
        ["石中剑", "你拔出了石中剑，获得物品，概率获得debuff"],
        ["铁匠", "可以强化物品"],
        ["破碎守卫", "战斗？交谈？无视？"],
        ["森林之门", "是否进入森林？"],
        ["未知", "一处未知之地"],
        ["人类营地", "锻炼？+随机属性休息？恢复生命"],
        ["火山喷发", "躲避？-少量生命；停留？-生命概率获得物品"],
        ["城墙", "修整？+生命+防御-速度；破坏？+攻击-幸运"],
        ["台风眼", "停留？+命中-生命；躲避？+暴击-闪避"],
        ["女巫之夜", "停留？+法力；躲避？获得物品"]
    ];
    // 各事件的具体效果
    areaData = [
        {
            func: () => {
                EventManager.Instance.empty[0].parent.active = true;
                // 渲染港口 3 物品 3 宠物 花费金币购买 点击图标购买 渲染“离开”按钮 7
                for (let i = 0; i < 6; i++) {
                    let id = <number>Utils.getRandomRange(0, 5);
                    (<Sprite>EventManager.Instance.empty[i].getComponent("cc.Sprite")).spriteFrame = id > 2 ? this.monsterFrames[id] : this.itemFrames[id];
                    if (i < 3) {
                        // 1表示物品 0表示宠物
                        EventManager.Instance.empty[i].once(Node.EventType.TOUCH_END, EventManager.Instance.buyCallback, [1, id])
                    } else {
                        EventManager.Instance.empty[i].once(Node.EventType.TOUCH_END, EventManager.Instance.buyCallback, [0, id])
                    }
                }
                EventManager.Instance.initButton("离开");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    EventManager.Instance.empty[0].parent.active = false;
                    EventManager.Instance.eventEnd()
                }, EventManager.Instance);
            }
        },
        {
            // 地牢入口
            func: () => { EventManager.Instance.nearNewMap() }
        },
        {
            // 邪恶塔
            func: () => { EventManager.Instance.meetGuard() }
        },
        {
            func: () => {
                // 离开当前小地图
                console.log("离开小地图");
                EventManager.Instance.eventEnd();
            }
        },
        {
            // 单人守卫塔
            func: () => { EventManager.Instance.meetGuard() }
        },
        {
            // 双士兵守卫塔
            func: () => { EventManager.Instance.meetGuard() }
        },
        {
            // 治疗塔
            func: () => { EventManager.Instance.meetGuard() }
        },
        {
            func: () => {
                // 渲染魔法传送门 2 传送 离开
                EventManager.Instance.initButton("传送", "离开");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, EventManager.Instance.transport, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, EventManager.Instance.eventEnd, EventManager.Instance);
            }
        },
        {
            // 迷宫
            func: () => { EventManager.Instance.nearNewMap() }
        },
        {
            func: () => {
                // 渲染神庙 3 种选项 祈祷 破坏 搜刮
                EventManager.Instance.initButton("祈祷", "破坏", "搜刮")
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    for (let i = 4; i < 6; i++) {
                        Hero.Instance.abilities[i] += Map.Instance.cur_map_floor * 2 + 2;
                        Hero.Instance.abilities[i - 2] -= Map.Instance.cur_map_floor * 2 + 2;
                    }
                    Hero.Instance.updateStat();
                    EventManager.Instance.eventEnd()
                }, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, () => {
                    Hero.Instance.abilities[2] += <number>Utils.getRandomRange(1, 10);
                    Hero.Instance.abilities[3] -= <number>Utils.getRandomRange(1, 10);
                    Hero.Instance.updateStat();
                    EventManager.Instance.eventEnd()
                }, EventManager.Instance);
                EventManager.Instance.btns[2].once(Node.EventType.TOUCH_END, () => {
                    Hero.Instance.gold += <number>Utils.getRandomRange(30, 70);
                    EventManager.Instance.eventEnd()
                }, EventManager.Instance);
            }
        },
        {
            func: () => {
                // 亡者复生 2 种 复活 离开
                EventManager.Instance.initButton("复活", "离开");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    if (Pet.Instance.lastDeadPet > -1) {
                        Hero.Instance.hp *= 0.8;
                        Pet.Instance.getPet(Pet.Instance.lastDeadPet);
                        Pet.Instance.lastDeadPet = -1;
                    }
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, EventManager.Instance.eventEnd, EventManager.Instance);
            }
        },
        {
            func: () => {
                // 石中剑 2 种 拔出 离开
                EventManager.Instance.initButton("拔出", "离开");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    if (Hero.Instance.mp > 30) {
                        Hero.Instance.mp -= 30;
                        Item.Instance.getItem(2);
                    }
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, EventManager.Instance.eventEnd, EventManager.Instance);
            }
        },
        {
            func: () => {
                // 铁匠台 2 种 强化 离开
                EventManager.Instance.initButton("学习", "离开");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    if (Hero.Instance.mp > 30) {
                        Hero.Instance.mp -= 30;
                        Move.Instance.getMove(Utils.getRandomRange(0, 23));
                        console.log("获得新技能");

                    }
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, () => {
                    Hero.Instance.exp += Hero.Instance.level * 40 + 20;
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
            }
        },
        {
            // 破碎塔
            func: () => { EventManager.Instance.meetGuard() }
        },
        {
            // 森林入口
            func: () => { EventManager.Instance.nearNewMap() }
        },
        {   // 未知之地（非地牢出入口、门和守卫） 2 种 进入 离开
            func: () => { EventManager.Instance.nearNewMap() }
        },
        {
            func: () => {
                // 营地 2 种 锻炼 休息
                EventManager.Instance.initButton("锻炼", "休息");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    if (Hero.Instance.hp >= Map.Instance.cur_map_floor * 2 + 10 && Hero.Instance.mp >= Map.Instance.cur_map_floor * 2 + 10) {
                        Hero.Instance.hp -= Map.Instance.cur_map_floor * 2 + 10;
                        Hero.Instance.mp -= Map.Instance.cur_map_floor * 2 + 10;
                        for (let i = 2; i < 4; i++) {
                            Hero.Instance.abilities[i] += Map.Instance.cur_map_floor * 2 + 2;
                        }
                    }
                    Hero.Instance.updateStat();
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, () => {
                    Hero.Instance.hp += Map.Instance.cur_map_floor * 10 + 20;
                    Hero.Instance.mp += Map.Instance.cur_map_floor * 5 + 10;
                    Hero.Instance.updateStat();
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
            }
        },
        {
            // 火山喷发
            func: () => { EventManager.Instance.stayOrLeave() }
        },
        {
            // 白色塔
            func: () => {
                // 2 种 修整 破坏
                EventManager.Instance.initButton("修整", "破坏");
                EventManager.Instance.btns[0].once(Node.EventType.TOUCH_END, () => {
                    Hero.Instance.abilities[3] += <number>Utils.getRandomRange(1, 10);
                    Hero.Instance.updateStat();
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
                EventManager.Instance.btns[1].once(Node.EventType.TOUCH_END, () => {
                    Hero.Instance.abilities[2] += <number>Utils.getRandomRange(1, 10);
                    Hero.Instance.updateStat();
                    EventManager.Instance.eventEnd();
                }, EventManager.Instance);
            }
        },
        {
            // 风洞
            func: () => { EventManager.Instance.stayOrLeave() }
        },
        {
            // 女巫之夜
            func: () => { EventManager.Instance.stayOrLeave() }
        },
    ]
    // 三层地图的怪物种类分布
    monsterLevel = [
        [1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 27, 28, 29, 31, 35, 36, 37],
        [4, 11, 13, 18, 22, 23, 24, 25, 26, 30, 32, 33, 34, 38, 41, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 17, 27, 28, 29, 31, 35, 36, 37],
        [0, 19, 20, 21, 39, 40, 42, 4, 11, 13, 18, 22, 23, 24, 25, 26, 30, 32, 33, 34, 38, 41],
        [0, 19, 20, 21, 39, 40, 42]
    ];
    // 怪物的文本说明
    monsterTips = [
        ["阿努比斯", "血防蓝"],
        ["眼镜蛇", "命暴"],
        ["树人长老", "血防"],
        ["海豚", "蓝命运"],
        ["双头龙", "攻速暴"],
        ["蜻蜓", "攻速"],
        ["鸭子", "血速运"],
        ["大象", "血防"],
        ["妖精", "蓝"],
        ["鱼人", "命"],
        ["飞鱼", "速"],
        ["弗兰肯斯坦", "血防攻"],
        ["青蛙", "运"],
        ["石像鬼", "防"],
        ["壁虎", "血速"],
        ["幽灵", "蓝速运"],
        ["墨鱼", "蓝"],
        ["金甲虫", "防运"],
        ["狮身人", "血防速"],
        ["狮鹫", "攻速暴"],
        ["死神", "攻速暴"],
        ["美杜莎", "蓝速暴"],
        ["美人鱼", "蓝速"],
        ["牛头人", "血防"],
        ["大头", "血防"],
        ["章鱼", "蓝运"],
        ["海盗船长", "速命暴"],
        ["北极熊", "血防"],
        ["螃蟹", "命暴"],
        ["蝎子", "暴"],
        ["丧尸", "攻"],
        ["雪人", "防"],
        ["斯巴达首领", "攻防"],
        ["斯巴达", "攻"],
        ["鲸鱼", "血防"],
        ["蜘蛛", "速"],
        ["老虎", "攻"],
        ["乌龟", "防"],
        ["独角兽", "攻速运"],
        ["吸血伯爵", "蓝攻速"],
        ["老巫婆", "蓝暴"],
        ["狼", "攻速"],
        ["巨龙", "攻速运暴"]
    ];
    // 怪物的数据
    monsterData = [
        {
            "a": [90, 60, 36, 36, 26, 16, 16, 16],
            "b": [76, 44, 19, 24, 12, 8, 8, 8],
            "e": 70,
            "g": 70
        },
        {
            "a": [50, 30, 30, 20, 25, 10, 10, 15],
            "b": [40, 18, 15, 10, 13, 4, 4, 9],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 30, 30, 30, 20, 10, 10, 10],
            "b": [50, 18, 15, 20, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 40, 20, 25, 15, 10, 10],
            "b": [40, 18, 25, 10, 13, 9, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 35, 43, 23, 23, 13, 18, 18],
            "b": [48, 21, 27, 12, 10, 6, 11, 11],
            "e": 50,
            "g": 50
        },
        {
            "a": [50, 30, 35, 20, 20, 10, 15, 10],
            "b": [40, 18, 20, 10, 8, 4, 9, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 30, 30, 20, 20, 15, 15, 10],
            "b": [50, 18, 15, 10, 8, 9, 9, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 30, 35, 20, 20, 10, 10, 10],
            "b": [50, 18, 20, 10, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 40, 30, 20, 20, 10, 10, 10],
            "b": [40, 28, 15, 10, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 30, 20, 25, 10, 10, 10],
            "b": [40, 18, 15, 10, 13, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 30, 20, 20, 10, 15, 10],
            "b": [40, 18, 15, 10, 8, 4, 9, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [70, 35, 43, 33, 23, 13, 13, 13],
            "b": [58, 21, 27, 22, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [50, 30, 30, 20, 20, 15, 10, 10],
            "b": [40, 18, 15, 10, 8, 9, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 35, 33, 33, 23, 13, 13, 13],
            "b": [48, 21, 17, 22, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [55, 30, 30, 20, 20, 10, 15, 10],
            "b": [45, 18, 15, 10, 8, 4, 9, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 40, 30, 20, 20, 15, 15, 10],
            "b": [40, 28, 15, 10, 8, 9, 9, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 40, 30, 20, 20, 10, 10, 10],
            "b": [40, 28, 15, 10, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 30, 25, 20, 15, 10, 10],
            "b": [40, 18, 15, 15, 8, 9, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [70, 35, 33, 28, 23, 13, 18, 13],
            "b": [58, 21, 17, 17, 10, 6, 11, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [70, 40, 46, 26, 26, 16, 26, 26],
            "b": [56, 24, 29, 14, 12, 8, 18, 18],
            "e": 70,
            "g": 70
        },
        {
            "a": [70, 40, 46, 26, 26, 16, 16, 26],
            "b": [56, 24, 29, 14, 12, 8, 8, 18],
            "e": 70,
            "g": 70
        },
        {
            "a": [70, 50, 36, 26, 26, 16, 26, 26],
            "b": [56, 34, 19, 14, 12, 8, 18, 18],
            "e": 70,
            "g": 70
        },
        {
            "a": [60, 45, 33, 23, 23, 13, 18, 13],
            "b": [48, 31, 17, 12, 10, 6, 11, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [70, 35, 33, 28, 23, 13, 13, 13],
            "b": [58, 21, 17, 18, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [90, 35, 33, 25, 23, 13, 13, 13],
            "b": [78, 21, 17, 18, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [60, 45, 33, 23, 23, 13, 13, 18],
            "b": [48, 31, 17, 12, 10, 6, 6, 16],
            "e": 50,
            "g": 50
        },
        {
            "a": [60, 35, 33, 23, 33, 13, 23, 18],
            "b": [48, 21, 17, 12, 20, 6, 16, 16],
            "e": 50,
            "g": 50
        },
        {
            "a": [55, 30, 30, 22, 20, 10, 10, 10],
            "b": [45, 18, 15, 12, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 30, 20, 22, 10, 10, 14],
            "b": [40, 18, 15, 10, 18, 4, 4, 14],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 30, 20, 20, 10, 10, 20],
            "b": [40, 18, 15, 10, 8, 4, 4, 20],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 35, 38, 23, 23, 13, 13, 13],
            "b": [48, 21, 37, 12, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [50, 30, 30, 30, 20, 10, 10, 10],
            "b": [40, 18, 15, 30, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 35, 38, 28, 23, 13, 13, 13],
            "b": [48, 21, 37, 27, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [60, 35, 38, 23, 23, 13, 13, 13],
            "b": [48, 21, 37, 22, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [70, 35, 33, 30, 23, 13, 13, 13],
            "b": [68, 21, 17, 26, 10, 6, 6, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [50, 30, 30, 20, 20, 10, 20, 10],
            "b": [40, 18, 15, 10, 8, 4, 18, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 35, 20, 20, 10, 10, 10],
            "b": [40, 18, 25, 10, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [50, 30, 30, 30, 20, 10, 10, 10],
            "b": [40, 18, 15, 25, 8, 4, 4, 4],
            "e": 30,
            "g": 30
        },
        {
            "a": [60, 35, 38, 23, 23, 13, 20, 20],
            "b": [48, 21, 27, 12, 10, 6, 16, 16],
            "e": 50,
            "g": 50
        },
        {
            "a": [70, 50, 36, 26, 26, 21, 21, 16],
            "b": [56, 44, 19, 14, 12, 13, 13, 8],
            "e": 70,
            "g": 70
        },
        {
            "a": [70, 50, 40, 26, 26, 16, 26, 16],
            "b": [56, 44, 40, 14, 12, 8, 26, 8],
            "e": 70,
            "g": 70
        },
        {
            "a": [60, 35, 33, 23, 23, 13, 23, 13],
            "b": [48, 21, 30, 12, 10, 6, 23, 6],
            "e": 50,
            "g": 50
        },
        {
            "a": [70, 40, 40, 26, 26, 26, 26, 26],
            "b": [56, 24, 40, 14, 18, 18, 18, 18],
            "e": 70,
            "g": 70
        }
    ];
    // buff的文本说明 21 个正面 24 个负面
    buffTips = [
        ["正义铁拳", "概率晕眩"],
        ["多重箭矢", "必定碎裂"],
        ["回旋", "必定缠绕"],
        ["临终一击", "濒死(生命<10%)时攻击翻倍"],
        ["七伤剑", "必定脆骨"],
        ["剃刀", "必定受伤"],
        ["全身抵抗", "加防御"],
        ["速度暴涨", "加速度"],
        ["燃烧生命", "掉血加攻击"],
        ["飞刀", "加攻加速"],
        ["毒刃", "必定腐蚀"],
        ["力量爆发", "全属性临时上涨"],
        ["咒术之剑", "概率惊爆"],
        ["闪亮之星", "立即恢复生命"],
        ["虚弱之剪", "必定致残"],
        ["超级狙击", "加暴击"],
        ["双刃", "概率双倍伤害"],
        ["生命祝福", "概率血翻倍"],
        ["天使之剑", "加攻击(依照血和防)"],
        ["宙斯之剑", "概率附加麻痹"],
        ["强心", "加生命加智慧"],
        ["致残", "减速度"],
        ["致盲", "减命中"],
        ["脆骨", "减防御"],
        ["受伤", "掉血"],
        ["缠绕", "减幸运"],
        ["低落", "减攻击"],
        ["愤怒", "加攻击减命中"],
        ["失智", "减蓝"],
        ["混乱", "概率攻击自己，攻击归0"],
        ["爆炸", "概率暴击伤自己"],
        ["晕眩", "攻击归0，减防御"],
        ["饥渴", "减攻加速"],
        ["腐蚀", "掉血，减防"],
        ["惊惧", "攻击归0，加速"],
        ["易损", "减攻击"],
        ["致盲", "减命中"],
        ["麻痹", "攻击归0，减幸运"],
        ["碎裂", "减防御"],
        ["蛛网", "减速度"],
        ["惊爆", "概率减全属性(智慧减免其效果)"],
        ["破碎武器", "减攻击"],
        ["碎片飞溅", "攻击反伤"],
        ["致命", "概率一击猝死"],
        ["失血", "减生命，减智慧"]
    ];
    // 物品的文本说明
    itemTips = [
        ["电光炸弹", "暴击率加成"],
        ["烤鸡", "立即恢复大量hp"],
        ["连锁炸弹", "命中加成"],
        ["火焰炸弹", "攻击加成"],
        ["冰霜炸弹", "防御加成"],
        ["钥匙", "打开宝箱"],
        ["上锁宝箱", "需要钥匙打开，打开后获得物品"],
        ["神灯", "许愿获得加成或物品或传送到下一层"],
        ["小肉块", "立即恢复中量hp"],
        ["纸鹤", "速度加成"],
        ["小蓝瓶", "战时恢复蓝"],
        ["小血瓶", "战时恢复血"],
        ["能量水晶", "战时后四项属性加成"],
        ["迷幻蘑菇", "战斗前随机获得buff或debuff"],
        ["藏宝图", "到达指定地点，获得物品奖励"],
        ["投掷炸弹", "幸运加成"],
        ["悬赏令", "击杀特定的怪物，获得加成或物品奖励"]
    ];
    // 英雄属性的文本说明
    statTips = [
        ["体质", "+0.1气血上限的防御,战后恢复0.1上限的生命"],
        ["智力", "某些技能效果加成,+0.1命中,战后+0.3经验加成,战后恢复0.1上限的魔法"],
        ["攻击", "范围波动±0.2"],
        ["防御", "1抵消敌方正常攻击,0.9抵消敌方暴击攻击,每次抵消防御衰减0.15"],
        ["命中", "未命中时+0.15命中，命中后恢复"],
        ["运气", "提供0.6暴击伤害,+0.1命中,0.5抵消敌方命中暴击率,0.7抵消暴击伤害"],
        ["速度", "决定先手权,+0.1攻击,+0.05命中,攻击频率最低0.5最高2"],
        ["暴击", "+0.5暴击伤害,触发暴击后暴击-0.15否则+0.1,暴击,攻击值波动为1.3~2并附加暴击伤害"]
    ];

    // 动态加载的8种精灵帧资源
    areaFrames: SpriteFrame[] = [];
    monsterFrames: SpriteFrame[] = [];
    buffFrames: SpriteFrame[] = [];
    debuffFrames: SpriteFrame[] = [];
    itemFrames: SpriteFrame[] = [];
    heroFrames: SpriteFrame[] = [];
    factionFrames: SpriteFrame[] = [];
    moveFrames: SpriteFrame[] = [];

    // 已加载的各部分总数
    loadCompleted: number = 0;

    onLoad() {
        // 设定帧率
        // game.frameRate = 30;
        this.loadTask();
        GameData.Instance = this;
    }

    loadTask() {
        resources.loadDir("area", SpriteFrame, null, (err, assets) => {
            this.areaFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("monster", SpriteFrame, null, (err, assets: [SpriteFrame]) => {
            this.monsterFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("buff", SpriteFrame, null, (err, assets) => {
            this.buffFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("debuff", SpriteFrame, null, (err, assets) => {
            this.debuffFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("item", SpriteFrame, null, (err, assets) => {
            this.itemFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("hero", SpriteFrame, null, (err, assets: [SpriteFrame]) => {
            this.heroFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("faction", SpriteFrame, null, (err, assets) => {
            this.factionFrames = assets;
            this.ifLoadCompleted();
        });
        resources.loadDir("move", SpriteFrame, null, (err, assets) => {
            this.moveFrames = assets;
            this.ifLoadCompleted();
        });
    }
    ifLoadCompleted() {
        this.loadCompleted++
        console.log(`已加载${this.loadCompleted}/8`);
        if (this.loadCompleted == 8) {
            MessageCenter.SendCustomMessage(MessageType.TYPE_UI, CommandType.COM_LOADING_COMPLETED);
        }
    }
}

/**
 * [1] Class member could be defined like this.
 * [2] Use `property` decorator if your want the member to be serializable.
 * [3] Your initialization goes here.
 * [4] Your update function goes here.
 *
 * Learn more about scripting: https://docs.cocos.com/creator/3.3/manual/zh/scripting/
 * Learn more about CCClass: https://docs.cocos.com/creator/3.3/manual/zh/scripting/ccclass.html
 * Learn more about life-cycle callbacks: https://docs.cocos.com/creator/3.3/manual/zh/scripting/life-cycle-callbacks.html
 */
